package com.houspace.utils;

public class LocalStringUtil {

    /**
     * 用给定参数args 格式化model 标记：{}
     * @param orginModel
     * @param args
     * @return
     */
    public static String format(String orginModel, Object...args){
        if(orginModel==null || "".equals(orginModel)){
            return orginModel;
        }
        String model = new String(orginModel);
        String result = model.replaceAll("\\{\\s\\}", "{}");
        if(args==null){
            return model.replaceFirst("\\{\\}", String.valueOf(args));
        }
        if(args.length==0){
            return model;
        }
        for(Object arg : args){
            if(result.indexOf("{}")==-1){
                break;
            }
            if(arg!=null){
                arg = arg.toString().replaceAll("\\$","\\\\\\$");
            }
            result = result.replaceFirst("\\{\\}", String.valueOf(arg));
        }
        return result;
    }


}
